
    ####################################################################
    ### Figures 2 and 3 - R code

    T1 <- 92
    T2 <- 114
    T <- length(T1:T2)  # number of congresses
    year.odd <- seq(from=1971, to=2016, by=2)

    Outputs <- read.csv("Figure2_3_data_Senate.csv", header=T)
    dim(Outputs)
    names(Outputs)
    

    ### Storages
    Dem.STD.IRT.mean <- Dem.STD.NOM.mean <- Dem.STD.IRT.median <- Dem.STD.NOM.median <- rep(NA, T)
    Rep.STD.IRT.mean <- Rep.STD.NOM.mean <- Rep.STD.IRT.median <- Rep.STD.NOM.median <- rep(NA, T)
    
    ##############################################################
    ### Loop over congresses

    for (t in T1:T2){
    
    # Subset for each Senate and Collect each party's median for each Senate

    Est <- subset(Outputs, congress==t)
    Dems <- subset(Est, Est$party==100)
    Reps <- subset(Est, Est$party==200)

    Dem.STD.IRT.median[t-(T1-1)] <- median(Est$STD.IRT[Est$party==100], na.rm=T)
    Rep.STD.IRT.median[t-(T1-1)] <- median(Est$STD.IRT[Est$party==200], na.rm=T)
    Dem.STD.NOM.median[t-(T1-1)] <- median(Est$STD.NOM[Est$party==100], na.rm=T)
    Rep.STD.NOM.median[t-(T1-1)] <- median(Est$STD.NOM[Est$party==200], na.rm=T)

    Dem.STD.IRT.mean[t-(T1-1)] <- mean(Est$STD.IRT[Est$party==100], na.rm=T)
    Rep.STD.IRT.mean[t-(T1-1)] <- mean(Est$STD.IRT[Est$party==200], na.rm=T)
    Dem.STD.NOM.mean[t-(T1-1)] <- mean(Est$STD.NOM[Est$party==100], na.rm=T)
    Rep.STD.NOM.mean[t-(T1-1)] <- mean(Est$STD.NOM[Est$party==200], na.rm=T)
    }
    
    ### End of the loop
    ############################################################################


    polar.index.STD.IRT <- abs(Dem.STD.IRT.mean - Rep.STD.IRT.mean)
    polar.index.STD.NOM <- abs(Dem.STD.NOM.mean - Rep.STD.NOM.mean)



    ##########################################################################
    # Do the same for the House Data
    
    Outputs <- read.csv("Figure2_3_data_House.csv", header=T)
    dim(Outputs)
    names(Outputs)
    

    ### Storages
    H.Dem.STD.IRT.mean <- H.Dem.STD.NOM.mean <- H.Dem.STD.IRT.median <- H.Dem.STD.NOM.median <- rep(NA, T)
    H.Rep.STD.IRT.mean <- H.Rep.STD.NOM.mean <- H.Rep.STD.IRT.median <- H.Rep.STD.NOM.median <- rep(NA, T)
    
    ##############################################################
    ### Loop over congresses

    for (t in T1:T2){
    
    # Subset for each Senate and Collect each party's median for each Senate

    Est <- subset(Outputs, congress==t)
    Dems <- subset(Est, Est$party==100)
    Reps <- subset(Est, Est$party==200)

    H.Dem.STD.IRT.median[t-(T1-1)] <- median(Est$STD.IRT[Est$party==100], na.rm=T)
    H.Rep.STD.IRT.median[t-(T1-1)] <- median(Est$STD.IRT[Est$party==200], na.rm=T)
    H.Dem.STD.NOM.median[t-(T1-1)] <- median(Est$STD.NOM[Est$party==100], na.rm=T)
    H.Rep.STD.NOM.median[t-(T1-1)] <- median(Est$STD.NOM[Est$party==200], na.rm=T)

    H.Dem.STD.IRT.mean[t-(T1-1)] <- mean(Est$STD.IRT[Est$party==100], na.rm=T)
    H.Rep.STD.IRT.mean[t-(T1-1)] <- mean(Est$STD.IRT[Est$party==200], na.rm=T)
    H.Dem.STD.NOM.mean[t-(T1-1)] <- mean(Est$STD.NOM[Est$party==100], na.rm=T)
    H.Rep.STD.NOM.mean[t-(T1-1)] <- mean(Est$STD.NOM[Est$party==200], na.rm=T)
    }
    
    ### End of the loop
    ############################################################################


    H.polar_index_STD_IRT <- abs(H.Dem.STD.IRT.mean - H.Rep.STD.IRT.mean)
    H.polar_index_STD_NOM <- abs(H.Dem.STD.NOM.mean - H.Rep.STD.NOM.mean)
    House.STD_medians <- rbind(H.Dem.STD.IRT.median,
                               H.Rep.STD.IRT.median,
                               H.Dem.STD.NOM.median,
                               H.Rep.STD.NOM.median)


    postscript("Figure2.eps", height=11, width=8, horizontal=F)
    par(mfrow=c(2, 1))
    plot(1:T, polar.index.STD.IRT, type='o', ylim=c(0,3.3), lty=1, col='black', xaxt="n", xlab="",ylab="")
    points(1:T, polar.index.STD.NOM, type='o', lty=2, col='black')
    axis(side=1, las=3, at=1:T, labels=year.odd, cex.axis=.8)
    legend('topleft', legend=c("Energy Policy", "General Ideology"), lty=c(1, 2), cex=.8)
    title(main="Senate",  font.main=1)
    plot(1:T, H.polar_index_STD_IRT, type='o', ylim=c(0,3.3), lty=1, col='black', xaxt="n", xlab="",ylab="")
    points(1:T, H.polar_index_STD_NOM, type='o', lty=2, col='black')
    axis(side=1, las=3, at=1:T, labels=year.odd, cex.axis=.8)
    legend('topleft', legend=c("Energy Policy", "General Ideology"), lty=c(1, 2), cex=.8)
    title(main="House",  font.main=1)
    dev.off()


    postscript("Figure3.eps", height=11, width=8, horizontal=F)
    par(mfrow=c(2, 1))
    plot(1:T, Dem.STD.IRT.median, type='o', pch=21, col='blue', ylim=c(-2,2), xaxt="n", xlab="",ylab="")
    points(1:T, Rep.STD.IRT.median,  type='o', pch=24, lty=1, col='red')
    points(1:T, Dem.STD.NOM.median,  type='o', pch=21, lty=2, col='blue')
    points(1:T, Rep.STD.NOM.median,  type='o', pch=24, lty=2, col='red')
    axis(side=1, las=3, at=1:T, labels=year.odd, cex.axis=.8)
    title(main="Senate",  font.main=1)
    legend('topleft', legend=c("Democrats - Energy Policy", "Republicans - Energy Policy", "Democrats - General Idealogy", "Republicans - General Ideology"), 
                                lty=c(1, 1, 2, 2), pch=c(21, 24, 21, 24), col=c('blue', 'red', 'blue', 'red'),cex=.8)
    plot(1:T, House.STD_medians[1,], type='o', pch=21, col='blue', ylim=c(-2,2), xaxt="n", xlab="",ylab="")
    points(1:T, House.STD_medians[2,],  type='o', pch=24, lty=1, col='red')
    points(1:T, House.STD_medians[3,],  type='o', pch=21, lty=2, col='blue')
    points(1:T, House.STD_medians[4,],  type='o', pch=24, lty=2, col='red')
    axis(side=1, las=3, at=1:T, labels=year.odd, cex.axis=.8)
    title(main="House",  font.main=1)
    legend('topleft', legend=c("Democrats - Energy Policy", "Republicans - Energy Policy", "Democrats - General Ideology", "Republicans - General Ideology"), 
                                lty=c(1, 1, 2, 2), pch=c(21, 24, 21, 24), col=c('blue', 'red', 'blue', 'red'),cex=.8)
    dev.off()

